package com.winona.ui;

import org.json.JSONObject;

import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.TextView;

import com.taplinker.client.R;
import com.taplinker.core.rpc.Result;
import com.taplinker.core.rpc.command.SimpleBaseCommand;
import com.taplinker.core.rpc.http.HttpTemplate;
import com.winona.Base1Activity;
import com.winona.ConstantValue;

public class AboutWeAcitivty extends Base1Activity {
	private ImageButton back;
	private TextView title;
	private TextView mContent;
	private Intent intent;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.about_we);
		findView();
		title.setText("关于我们");
		setLinstener();
		getContent();
	}

	private void getContent() {
		new SimpleBaseCommand() {

			@Override
			public Result go() {
				return new HttpTemplate().exchange(ConstantValue.COMMON
						+ "about/us/find/new");
			}

			@Override
			public void yes(Result result) {
				try {
					JSONObject jo = new JSONObject(result.object.toString());
					mContent.setText(""
							+ jo.getJSONObject("body").getString("content"));
				} catch (Exception e) {
					e.printStackTrace();
				}
			}

			@Override
			public void no(Result result) {
			}

		}.execute();
	}

	private void setLinstener() {
		back.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				intent = new Intent(AboutWeAcitivty.this, AboutActivity.class);
				startActivity(intent);
				overridePendingTransition(R.anim.input, R.anim.out);
			}
		});

	}

	private void findView() {
		back = (ImageButton) findViewById(R.id.about_me_back);
		title = (TextView) findViewById(R.id.about_me_title);
		mContent = (TextView) findViewById(R.id.content_tv);
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { // 按下的如果是BACK，同时没有重复
			startActivity(AboutActivity.class);
			return true;
		}

		return super.onKeyDown(keyCode, event);
	}
}
